package com.collection.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5加密工具类
 * @author 冯勇
 *
 */
public class EncryptUtil {

	/**
	 * MD5加密
	 * @param input 加密前的字符串
	 * @return 加密后字符串
	 */
	public static String md5(String input) {
		if (input == null) {
			return "";
		} else {
			String value = null;
			MessageDigest md5 = null;

			try {
				md5 = MessageDigest.getInstance("MD5");
				sun.misc.BASE64Encoder baseEncoder = new sun.misc.BASE64Encoder();
				value = baseEncoder.encode(md5.digest(input.getBytes("utf-8")));
			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			return value;
		}

	}
}
